<?php

$lock = new swoole_lock(SWOOLE_MUTEX);
echo "创建互斥锁\n";
$lock->lock();
if (pcntl_fork() > 0) {
    sleep(1);
    $lock->unlock();
} else {
    echo "子进程等待锁\n";
    $lock->lock();
    echo "子进程获取锁\n";
    $lock->unlock();
    exit("子进程退出");
}
echo "主进程释放锁";
unset($lock);
sleep(1);
echo "子进程退出";
